package com.wingsoft.homeFlow.bo;

import com.wingsoft.common.exception.ServiceException;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.Objects;

/**
 * @author Wingsoft
 * @description 针对表【HOME_FLOW_SOURCE(工作流数据源)】的数据库映射
 */
@Data
public class HomeFlowSourceBo {

    @ApiModelProperty("ID")
    private String id;

    @ApiModelProperty("数据源名称")
    private String name;

    @ApiModelProperty("数据源类型：1-oracle，2-mysql，3-api，4-sql server，5-gauss")
    private Integer type;

    @Getter
    @AllArgsConstructor
    public enum TypeEnum {
        ORACLE(1, "oracle"),
        MYSQL(2, "mysql"),
        API(3, "api"),
        SQL_SERVER(4, "sql server"),
        GAUSS(5, "gauss"),
        ;

        private final Integer code;
        private final String desc;

        public static TypeEnum getEnumByCode(Integer code) {
            for (TypeEnum value : TypeEnum.values()) {
                if (Objects.equals(value.code, code)) {
                    return value;
                }
            }
            throw new ServiceException("数据源类型 枚举值不存在: " + code);
        }
    }

    @ApiModelProperty("驱动类")
    private String driver;

    @ApiModelProperty("地址")
    private String address;

    @ApiModelProperty("账号")
    private String username;

    @ApiModelProperty("密码")
    private String password;

}